package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Reviewer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class ReviewerDaoImpl implements ReviewerDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addReviewer(Reviewer reviewer) {
        String sql="insert into Reviewer values(?,?,?,?,?,?,?,0,now())";
        return jdbcTemplate.update(sql,
                reviewer.getRevID(),
                reviewer.getRevCount(),
                reviewer.getRevPassword(),
                reviewer.getRevName(),
                reviewer.getRevSex(),
                reviewer.getRevBirth(),
                reviewer.getRevPhone());
    }

    public int deleteReviewerByID(String revID) {
        String sql="update reviewer set LogicalAddDel=0,LastModification=now() where RevID=?";
        return jdbcTemplate.update(sql,revID);
    }


    public int updateReviewer(Reviewer reviewer) {
        String sql="update reviewer set RevID=?,RevCount=?,RevPassword=?," +
                "RevName=?,RevSex=?,RevBirth=?,RevPhone=?,LastModification=now() where RevID=?";
        return jdbcTemplate.update(sql,reviewer.getRevID(),
                reviewer.getRevCount(),
                reviewer.getRevPassword(),
                reviewer.getRevName(),
                reviewer.getRevSex(),
                reviewer.getRevBirth(),
                reviewer.getRevPhone(),reviewer.getRevID());
    }


    public List<Map<String,Object>> selectReviewerByID(String revID) {
        String sql = "select * from reviewer where RevID = ?";
        return jdbcTemplate.queryForList(sql,revID);
    }



    public List<Map<String,Object>> getAllReviewer() {
        String sql="select * from reviewer";
        return jdbcTemplate.queryForList(sql);
    }
}
